package com.gls.service.demo.controller;

import com.gls.api.service.demo.dto.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

/**
 * @author lizhiyong
 */
@Slf4j
@RestController
public class HelloController {

    @Autowired
    DiscoveryClient discoveryClient;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello() {
        String services = "Services: " + discoveryClient.getServices();
        log.info(services);
        return "Hello World";
    }

    @RequestMapping(value = "/hello1", method = RequestMethod.GET)
    public String hello(@RequestParam String name) {
        String services = "Services: " + discoveryClient.getServices();
        log.info(services);
        return "Hello " + name;
    }

    @RequestMapping(value = "/hello2", method = RequestMethod.GET)
    public User hello(@RequestHeader String name, @RequestHeader Integer age) {
        String services = "Services: " + discoveryClient.getServices();
        log.info(services);
        return new User(name, age);
    }

    @RequestMapping(value = "/hello3", method = RequestMethod.POST)
    public String hello(@RequestBody User user) {
        String services = "Services: " + discoveryClient.getServices();
        log.info(services);
        return "Hello " + user.getName() + ", " + user.getAge();
    }
}
